<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<?php
require_once('../../includes/classes/core.php');
require_once('../../includes/classes/barcode/tfpdf.php');

$object_id = $_REQUEST['id'];

$res = mysql_query("	SELECT  		`production`.`code` AS `barcode`,
										`production`.`name` AS `name`,
										`production`.`code` AS `code`,
										`production_category`.`name` AS `category`,
										ROUND(SUM(`reserve`.`quantity` - `reserve`.`sold`), 2) as `quantity`,
										'' AS `real_quantity`
						FROM  			`reserve`
						LEFT JOIN		`object` ON	`reserve`.`object_id` = `object`.`id` 
						LEFT JOIN     	`production` ON	`reserve`.`production_id` = `production`.`id`
						LEFT JOIN     	`production_unit` ON `production`.`unit` = `production_unit`.`id`
						LEFT JOIN		`production_category` ON `production`.`category` = `production_category`.`id`
						WHERE			`reserve`.`quantity` - `reserve`.`sold` != 0 && ISNULL(`reserve`.`barcode`) && `object`.`id` = '$object_id'
						GROUP BY      	`reserve`.`object_id`, `reserve`.`production_id`");

echo 'ობიექტი: <u><b>'.getObject($object_id).'</b></u>&nbsp&nbsp&nbsp&nbsp&nbsp';
echo 'თარიღი: <u><b>'.date('Y-m-d H:i:s').'</b></u>';

echo '<table  style="width: 100%; "  cellspacing="0" cellpadding="6">
		<tr style="border-spacing: 10px;" >
			<td style=" font-size: 10px; width: 25%; border-bottom:1px solid black; border-top:1px solid black;"><b>შტრიხკოდი</b></td>
			<td style=" font-size: 10px; width: 15%; border-bottom:1px solid black; border-top:1px solid black;"><b>კოდი</b></td>
			<td style="font-size: 10px; width: 25%; border-bottom:1px solid black; border-top:1px solid black;"><b>დასახელება</b></td>
			<td style="font-size: 10px; width: 15%; border-bottom:1px solid black; border-top:1px solid black;"><b>კატეგორია</b></td>
			<td style="font-size: 10px; width: 8%; border-bottom:1px solid black; border-top:1px solid black;"><b>რაოდ.</b></td>
			<td style="font-size: 10px; width: 15%; border-bottom:1px solid black; border-top:1px solid black;"><b>ფაქტ. რაოდ.</b></td>
		</tr>';

while ($row = mysql_fetch_assoc($res)) {
	echo  	'<tr>';
	echo	'<td style=" font-size: 10px; width: 25%; border-bottom:1px solid black; position: relative; margin-left: -10px;"><img alt="testing" src="barcode.php?text='.$row['barcode'].'" /></td>';
	echo 	'<td style=" font-size: 10px; width: 15%; border-bottom:1px solid black;">'.$row['code'].'</td>';
	echo 	'<td style=" font-size: 10px; width: 25%; border-bottom:1px solid black;">'.$row['name'].'</td>';
	echo 	'<td style=" font-size: 10px; width: 15%; border-bottom:1px solid black;">'.$row['category'].'</td>';
	echo 	'<td style=" font-size: 10px; width: 8%; border-bottom:1px solid black;">'.$row['quantity'].'</td>';
	echo 	'<td style=" font-size: 10px; width: 115%; border-bottom:1px solid black;">'.$row['real_quantity'].'</td></tr>';
}

echo '</table>'; 

function getObject($object_id){
	$res = mysql_query("
			SELECT object.name
			FROM   object
			WHERE object.id = '$object_id'");
	
	return mysql_result($res, 0, 'name');
}
	
?>